package com.lzq.model.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/19 15:04
 * @updateUser : modify
 * @updateTime : 2022/11/19 15:04
 * @updateRemark :
 */
public class ProxyFactory {
    private Station station = new Station();

    public SellInterface getSellInterface() {
        SellInterface sellProxy = (SellInterface) Proxy.newProxyInstance(
                station.getClass().getClassLoader(),
                station.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("接口方法名称：" + method.getName());
                        return method.invoke(station, args);
                    }
                }
        );
        return sellProxy;
    }
}

class Test {
    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();
        SellInterface sellInterface = proxyFactory.getSellInterface();
        sellInterface.sell();

        System.out.println(sellInterface.getClass());
        while (true) {
            
        }
    }
}